﻿Public Class Glass

    <System.Runtime.InteropServices.DllImport("dwmapi.dll")> _
   Private Shared Function DwmIsCompositionEnabled(ByRef en As Integer) As Integer
    End Function

    <System.Runtime.InteropServices.DllImport("dwmapi.dll")> _
   Private Shared Function DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef margin As MARGINS) As Integer
    End Function

    Private Left As Integer = 0
    Private Right As Integer = 0
    Private Top As Integer = 0
    Private Bottom As Integer = 0

    Public Shared Sub SetGlass(ByVal Form As Form)
        Dim en As Integer = 0
        Dim mg As New MARGINS()
        mg.m_Bottom = -1
        mg.m_Left = -1
        mg.m_Right = -1
        mg.m_Top = -1
        'make sure you are not on a legacy OS 
        If System.Environment.OSVersion.Version.Major >= 6 Then
            DwmIsCompositionEnabled(en)
            'check if the desktop composition is enabled
            If en > 0 Then
                DwmExtendFrameIntoClientArea(Form.Handle, mg)
            Else
                Throw New ApplicationException("This computer does not have the areo interface enabled.")
            End If
        Else
            Throw New ApplicationException("This computer does not have the areo theme capibility.")
        End If
        'make sure you are not on a legacy OS 
        If System.Environment.OSVersion.Version.Major >= 6 Then
            DwmIsCompositionEnabled(en)
            'check if the desktop composition is enabled
            If en > 0 Then
                DwmExtendFrameIntoClientArea(Form.Handle, mg)
            Else
                Throw New ApplicationException("This computer does not have the areo interface enabled.")
            End If
        Else
            Throw New ApplicationException("This computer does not have the areo theme capibility.")
        End If

    End Sub

    Private Enum SizeOfGlass
        All = 1
        Custom = 2
    End Enum

    Sub New(ByVal Form As Form, ByVal Auto As Boolean, Optional ByVal Top As Integer = 0, Optional ByVal Bottom As Integer = 0, Optional ByVal Left As Integer = 0, Optional ByVal Right As Integer = 0)
        If Auto = True Then
            SetGlass(Form)
        Else
            Me.Top = Top
            Me.Bottom = Bottom
            Me.Left = Left
            Me.Right = Right
            SetGlass(Form)
        End If
    End Sub

    Sub New()

    End Sub

    Private Structure MARGINS
        Public m_Left As Integer
        Public m_Right As Integer
        Public m_Top As Integer
        Public m_Bottom As Integer
    End Structure
End Class
